/*
 *  Copyright 2011 Iurii Dunko, Iana Potochniak.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */

package org.opu.yyminijava.syntaxtree;

import org.opu.yyminijava.visitor.Visitor;


/**
 *
 * @author Iurii Dunko
 * @author Iana  Potochniak
 */
public class ClassDeclaration implements Rule {

    private static final long serialVersionUID = 1323110697107L;

    private Modifiers modifiers;
    private String name;
    private ClassBody classBody;

    private ClassType superName;
    private ClassDeclaration superClass;

    public ClassDeclaration() {
    }

    public ClassDeclaration(Modifiers modifiers, String name, ClassType superName,
            ClassBody classBody) {
        this.modifiers = modifiers;
        this.name = name;
        this.superName = superName;
        this.classBody = classBody;
    }

    public ClassDeclaration getSuperClass() {
        return superClass;
    }

    public void setSuperClass(ClassDeclaration superClass) {
        this.superClass = superClass;
        this.superName = null;
    }
    
    public Modifiers getModifiers() {
        return modifiers;
    }

    public void setModifiers(Modifiers modifiers) {
        this.modifiers = modifiers;
    }

    public ClassBody getClassBody() {
        return classBody;
    }

    public void setClassBody(ClassBody classBody) {
        this.classBody = classBody;
        this.classBody.setClazz(this);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public ClassType getSuperName() {
        return superName;
    }

    public void setSuperName(ClassType superName) {
        this.superName = superName;
        this.superClass = null;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final ClassDeclaration other = (ClassDeclaration) obj;
        if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 97 * hash + (this.name != null ? this.name.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        return String.valueOf(name);
    }

    @Override
    public void accept(Visitor visitor) {
        visitor.visit(modifiers);
        visitor.visit(classBody);
    }
}
